package com.yangzihao.user.web;

import com.yangzihao.user.pojo.PatternProperties;
import com.yangzihao.user.pojo.User;
import com.yangzihao.user.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Locale;

@Slf4j
@RestController
@RequestMapping("/user")
@RefreshScope
public class UserController {

    @Autowired
    private UserService userService;
//    @Value("${pattern.dateformat}")
//    private String dateformat;

    @Autowired
    private PatternProperties patternProperties;


    @GetMapping("prop")
    public PatternProperties patternProperties(){
        return patternProperties;
    }


    @GetMapping("/now")
    public String now(){
        return LocalDateTime.now().format(DateTimeFormatter.ofPattern(patternProperties.getDateformat(), Locale.CHINA));
    }

    /**
     * 路径： /user/110
     *
     * @param id 用户id
     * @return 用户
     */
    @GetMapping("/{id}")
    public User queryById(@PathVariable("id") Long id) {
        return userService.queryById(id);
    }


    @GetMapping("/updateById")
    public Integer updateById(Long id){
     return   userService.updateById(id);
    }


    @GetMapping("/testGateWayFilters")
    public String testGateWayFilters(@RequestHeader(value = "addtest",required = false) String addtest){
        System.out.println(addtest);
        return addtest;
    }
    @GetMapping("/testGateWayFilters1")
    public String testGateWayFilters1(@RequestHeader(value = "addtest1",required = false) String addtest1){
        System.out.println(addtest1);
        return addtest1;
    }

}







